package bsh.meta;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.objectweb.asm.Opcodes;

/**
 * {@link MethodDescriptor} para metodos que estao sendo compilados
 * 
 * @author takeshi
 */
public class UnfinishedMethodDescriptor extends AbstractMethodDescriptor implements MethodDescriptor {

    private final TypeWrapper declaringType;

    private final String name;

    private final List<TypeWrapper> parameterTypes;

    private final List<TypeWrapper> declaredExceptions;

    private final TypeWrapper returnType;

    /**
     * @param declaredExceptions {@link TypeWrapper}
     * @param declaringType {@link TypeWrapper}
     * @param name nome do metodo
     * @param parameterTypes {@link TypeWrapper}
     * @param returnType {@link TypeWrapper}
     */
    public UnfinishedMethodDescriptor(TypeWrapper[] declaredExceptions, TypeWrapper declaringType, String name,
            TypeWrapper[] parameterTypes, TypeWrapper returnType) {
        super();
        this.declaredExceptions =
                this.declaredExceptions == null ? Collections.<TypeWrapper> emptyList() : new ArrayList<TypeWrapper>(
                        Arrays.asList(declaredExceptions));
        this.declaringType = declaringType;
        this.name = name;
        this.parameterTypes = new ArrayList<TypeWrapper>(Arrays.asList(parameterTypes));
        this.returnType = returnType;
    }

    /**
     * {@inheritDoc}
     */
    public TypeWrapper declaringType() {
        return this.declaringType;
    }

    /**
     * {@inheritDoc}
     */
    public String methodName() {
        return this.name;
    }

    /**
     * {@inheritDoc}
     */
    public int modifiers() {
        return Opcodes.ACC_PUBLIC;
    }

    /**
     * {@inheritDoc}
     */
    public List<? extends TypeWrapper> parameterTypes() {
        return this.parameterTypes;
    }

    /**
     * {@inheritDoc}
     */
    public TypeWrapper returnType() {
        return this.returnType;
    }

    /**
     * {@inheritDoc}
     */
    public List<TypeWrapper> throwsClauses() {
        return new ArrayList<TypeWrapper>(this.declaredExceptions);
    }

    /**
     * {@inheritDoc}
     */
    public boolean isVarArgs() {
        return false;
    }

}
